package com.boyi.converter;

import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;

import java.util.HashSet;
import java.util.Set;

/**
 * @author tingwen
 * @description 时间转换器
 * @date 2019-09-07 13:35
 **/
public class SensitiveFieldConverter  implements ConditionalGenericConverter {


    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        Set<ConvertiblePair> convertiblePairs = new HashSet<>();
        ConvertiblePair stringToStringEncrypt = new ConvertiblePair(String.class, String.class);
        convertiblePairs.add(stringToStringEncrypt);
        return convertiblePairs;
    }

    @Override
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
        if (targetType.getType() == String.class){
            System.out.println("source = " + source);
        }
        return source;
    }

    @Override
    public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
        if (sourceType.getAnnotation(SensitiveEncrypt.class)!=null){
            return true;
        }
        return false;
    }

}